//
//  WatchDetailMarketCell.m
//  ZITHER
//
//  Created by imac on 2018/6/13.
//  Copyright © 2018年 MinesTime. All rights reserved.
//

#import "WatchDetailMarketCell.h"
#import "MarketSubAuctionCell.h"
static NSString *const MarketSubAuctionCellID = @"MarketSubAuctionCell";
@interface WatchDetailMarketCell () <UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UIView *priceBGView;
@property (weak, nonatomic) IBOutlet UIView *cornerView;

/** 拍卖组View */
@property (weak, nonatomic) IBOutlet UIView *auctionSectionView;
/** 拍卖TableView */
@property (weak, nonatomic) IBOutlet UITableView *auctionTableView;
/** 根据拍卖个数调整TableView高度 */
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *auctionTableViewHeightLayout;
/** 价格风向标 年月  */
@property (weak, nonatomic) IBOutlet UILabel *priceTrendDateLabel;
/** 二手价 */
@property (weak, nonatomic) IBOutlet UILabel *secondPriceLabel;
/* 比3个月前 */
@property (weak, nonatomic) IBOutlet UILabel *trendLabel1;
/* 比6个月前 */
@property (weak, nonatomic) IBOutlet UILabel *trendLabel2;
/* 比12个月前 */
@property (weak, nonatomic) IBOutlet UILabel *trendLabel3;

@end
@implementation WatchDetailMarketCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    [_priceBGView setCornerRadiusWithRadius:4 isMasks:NO];
    [_priceBGView setShadowType1WithColor:[UIColor defaultShadowColor] offset:CGSizeZero opacity:1 radius:3];
    [_cornerView setCornerRadiusWithRadius:4 isMasks:YES];
    
    [_trendLabel1 setCornerRadiusWithRadius:2 isMasks:YES];
    [_trendLabel2 setCornerRadiusWithRadius:2 isMasks:YES];
    [_trendLabel3 setCornerRadiusWithRadius:2 isMasks:YES];
    
}
+ (CGFloat)watchDetailMarketCellHeightWithModel:(WatchDetailBaseModel_Info_HQInfo *)model {
    
    return model.marketCellHeight;
}
#pragma mark - Setter
- (void)setModel:(WatchDetailBaseModel_Info_HQInfo *)model {
    _model = model;
    model.marketCellHeight = kFLOAT(266); //风向标高度
    NSLog(@"%@",model);
    _priceTrendDateLabel.text = model.twoHandPriceInfo.priceMonth;
    _secondPriceLabel.text = model.twoHandPriceInfo.lastPrice;
    
    
    _trendLabel1.text = model.twoHandPriceInfo.threePriceTrendTitle;
    _trendLabel1.backgroundColor = model.twoHandPriceInfo.threePriceTrendTitleColor;
    
    _trendLabel2.text = model.twoHandPriceInfo.sixPriceTrendTitle;
    _trendLabel2.backgroundColor = model.twoHandPriceInfo.sixPriceTrendTitleColor;
    
    _trendLabel3.text = model.twoHandPriceInfo.twelvePriceTrendTitle;
    _trendLabel3.backgroundColor = model.twoHandPriceInfo.twelvePriceTrendTitleColor;
    
    
    if (model.auctionList && model.auctionList.count > 0) {
        [_auctionSectionView setHidden:NO];
        model.marketCellHeight += kFLOAT(40); //组头高度
        CGFloat cellTotalHeight = model.auctionList.count * kFLOAT(210);
        model.marketCellHeight += cellTotalHeight; //每个拍卖的高度
        _auctionTableViewHeightLayout.constant = cellTotalHeight;
    } else {
        [_auctionSectionView setHidden:YES];
    }
    [self.auctionTableView reloadData];
    
}
- (void)setAuctionTableView:(UITableView *)auctionTableView {
    _auctionTableView = auctionTableView;
    
    _auctionTableView.delegate = self;
    _auctionTableView.dataSource = self;
    [_auctionTableView registerNib:[UINib nibWithNibName:NSStringFromClass([MarketSubAuctionCell class]) bundle:nil] forCellReuseIdentifier:MarketSubAuctionCellID];
}
#pragma mark - UITableView Delegate/DataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.model.auctionList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    MarketSubAuctionCell *cell = [tableView dequeueReusableCellWithIdentifier:MarketSubAuctionCellID];
    cell.model = self.model.auctionList[indexPath.row];
    return cell;
    
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return kFLOAT(210);
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 0.01;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 0.01;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    return [[UIView alloc] init];
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    return [[UIView alloc] init];
}
@end
